package com.example.xianzhi.controller.API;


import cn.hutool.json.JSONUtil;
import com.example.xianzhi.entity.TbUser;
import com.example.xianzhi.service.UserSercive;
import com.example.xianzhi.service.impl.UserSerciveImpl;
import org.lanqiao.mvc.entity.ModelAndView;
import org.lanqiao.mvc.entity.YockMvcAnnotation;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;


@YockMvcAnnotation.Controller("/apl_User")
public class Apl_UserController {

    //用户业务层
    private UserSercive user = new UserSerciveImpl();



    /**
     * 查询用户信息
     * @param request
     * @param response
     * @return
     */
    @YockMvcAnnotation.RequestMapping("/selectuser.do")
    @YockMvcAnnotation.ResponseBody
    public String selectuser(
            HttpServletRequest request,
            HttpServletResponse response,
            @YockMvcAnnotation.RequestParam(name = "user_id") int user_id
    ) {


        //允许的请求的域是*，代表所有
        response.setHeader("Access-Control-Allow-Origin","*");
        //告诉前端返回来的是一个json数据
        response.setContentType("application/json;charset=utf-8");
        // 保存用户信息的集合
        Map<String, Object> map = new HashMap<>();
        //查询用户信息
        TbUser tbUser = user.selectUser(user_id);

        map.put("code",200);
        map.put("data",tbUser);

        String jsonStr = JSONUtil.toJsonStr(map);



        return jsonStr;
    }


}
